package com.hengxinguotong.zhihuichengjian.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;

import com.hengxinguotong.zhihuichengjian.R;
import com.hengxinguotong.zhihuichengjian.bean.EnvironmentWarning;
import com.hengxinguotong.zhihuichengjian.treeview.RecyclerAdapter;
import com.hengxinguotong.zhihuichengjian.widget.font.HXTextView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @CopyRight 恒信国通信息科技
 * @Author WuLei
 * @Date 2019/2/25
 *
 * 环境详情违章列表适配器
 */

public class EnvironmentDataWarningListAdapter extends RecyclerAdapter<EnvironmentWarning, EnvironmentDataWarningListAdapter.EnvironmentDataWarningListViewHolder> {

    public EnvironmentDataWarningListAdapter(Context context, List<EnvironmentWarning> dataList) {
        super(context, dataList);
    }

    @Override
    public EnvironmentDataWarningListViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(context, R.layout.item_environment_data_list_warning, null);
        return new EnvironmentDataWarningListViewHolder(view);
    }

    @Override
    public void onBindViewHolder(EnvironmentDataWarningListViewHolder holder, int position) {
        holder.bindData(position);
    }

    public class EnvironmentDataWarningListViewHolder extends RecyclerAdapter.BaseViewHolder<EnvironmentWarning>{
        @BindView(R.id.environment_warning_type_tv)
        HXTextView environmentWarningTypeTv;
        @BindView(R.id.environment_warning_tv)
        HXTextView environmentWarningTv;
        @BindView(R.id.create_time_tv)
        HXTextView createTimeTv;

        public EnvironmentDataWarningListViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }

        @Override
        public void bindData(int position) {
            final EnvironmentWarning environmentWarning = dataList.get(position);
            if(environmentWarning.getType().equals("预警")){
                environmentWarningTypeTv.setEnabled(true);
                environmentWarningTypeTv.setText("预警");
            }else {
                environmentWarningTypeTv.setEnabled(false);
                environmentWarningTypeTv.setText("报警");
            }
            environmentWarningTv.setText(environmentWarning.getClassify() + "  " + environmentWarning.getValue());
            createTimeTv.setText(environmentWarning.getAcquisitionTime());
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    onClickListener.onClick(environmentWarning);
                }
            });
        }
    }
}
